home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet Toolkit
/
Internet Toolkit.iso
/
info
/
lumberja
/
lumberjak
< prev
Wrap
Text File
|
1993-04-05
|
6KB
|
203 lines
#!/usr/bin/perl -- # -*-Perl-*-
# local defines
$OPERPASSFILE = '/other/irc/lib/robot.pw';
# variables:
# $port, $server - server to connect to
# $servername - name of the server we're on
# (what the server calls itself)
# $nick - nickname
# $fullname - full name field
# $username - username to use with server
# S - socket file handle
# $source - source of a remote message
# $quitflag - set to 1 to quit
# $lord - my lord and liege
# $magicword - how do you make me leave?
# $eavesdrop - forward MSGs to lord
# $biff - REALLY COOL MODE DOOD
# $verbose - debugging mode
# $talk - like stuff a lot
# $greet - say hi to people
# %lastpriv - last msg from whoever
# primitive support functions
sub Upcase { # upcase the arg & return it
local($string) =@_;
$string =~ tr/a-z/A-Z/;
$string;
}
sub StripLeadingColon { # strips the leading colon if any from $arg
local($string) = @_; # and returns the str without the :
$string =~ s/^://; # (written because IRC has so many :msgs)
$string;
}
# cmdline parsing now uses getopt.pl for ease of expansion
$| = 1; # allow for debug messages
push(@INC,'/home/ckd/lib/perl');
require 'getopts.pl';
require 'ircclient.pl';
require 'ctime.pl';
do Getopts('p:s:n:f:u:l:c:d:o');
# port, server, nick, fullname, username, lord, channel, magicword, dumpfile
# Booleans: o = oper, e = eavesdrop, v = verbose-debug, b = biff, t = talk,
# g = greet, r= revenger
$port = $opt_p || $ENV{'IRCPORT'} || 6667;
$server = $opt_s || $ENV{'IRCSERVER'} || 'eff.org';
$nick = $opt_n || $ENV{'IRCAUTONICK'} || 'LumberJak';
$fullname = $opt_f || $ENV{'IRCAUTONAME'} || 'I log all night and I log all day';
$username = $opt_u || getlogin || (getpwuid($<))[0];
$lord = $opt_l || $ENV{'IRCNICK'} || $ENV{'USER'} || (getpwuid($<))[0] ||
die "The death of God left the angels in a strange position";
$channel = $opt_c || "#Twilight_Zone";
#$magicword = $opt_m || 'Bernstein';
$delay = 1;
$dumpfile = $opt_d || '/home/hrose/trillian/ircstuff/bot.dumplog';
#$eavesdrop = $opt_e; $debug = $opt_v; $biff = $opt_b;
#$talk = $opt_t; $greet = $opt_g; $vengeance = $opt_r;
chop($operpass = `head -1 $OPERPASSFILE`);
open(LOGFILE,">>$dumpfile");
select ((select (LOGFILE),$|=1)[0]);
&ircclient'bindsocket('S',$server,$port);
# now we have a socket connected to the server, time to play
# first, signon as a client
&ircclient'nick($nick);
&ircclient'user($username,$username,$server,$fullname);
if ($operpass) {
&ircclient'oper('robotman',$operpass);
}
&ircclient'join($channel);
# next, completely ignore the message of the day
# while getting the server's name for itself
munchmotd:
while (<S>) {
chop;
($servername) = m/.*Your host is ([^ ,]+),.*/
if m/Your host is/;
if (( m!End of /MOTD command! ) ||
( m!Message-of-today is missing! )) {
last munchmotd;
}
}
$servername = $server unless $servername; # do some simple trapping for oldies
mainloop: while (<S>) {
chop;
$_ = ":$servername $_" unless /^:/;
($source, $command, $parms) = split(/ /,$_,3);
$source = &StripLeadingColon($source);
$cmd = &Upcase($command);
cmdcase: # treated as a switch/case type thingy
{ # as long as you're careful about eq
if ($cmd eq 'CHANNEL') {&ParseChan($source,$cmd,$parms);
last cmdcase;};
if ($cmd eq 'JOIN') {&ParseChan($source,$cmd,$parms);
last cmdcase;};
if ($cmd eq 'PART') {&ParseChan($source,$cmd,$parms);
last cmdcase;};
if ($cmd eq 'INVITE') {&ParseInvite($source,$parms);
last cmdcase;};
if ($cmd eq 'MSG') {&ParseMsg($source,$parms);
last cmdcase;};
if ($cmd eq 'NOTICE') {&ParseNotice($source,$parms);
last cmdcase;};
if ($cmd eq 'PING') {&ircclient'pong($nick);
last cmdcase;};
if ($cmd eq 'PRIVMSG') {&ParsePriv($source,$parms);
last cmdcase;};
if ($cmd eq 'WALLOPS') {&ParseWallops($source,$parms);
last cmdcase;};
if ($cmd eq 'WALL') {&ParseWall($source,$parms);
last cmdcase;};
if ($cmd eq 'QUIT') {&ParseQuit($source,$parms);
last cmdcase;};
if ($cmd eq 'NAMREPLY') {&ParseNamReply($source,$parms);
last cmdcase;};
}
} continue {
if ($quitflag)
{&Quit;}
}
# nifty parse stuff
sub ParseChan {
local ($who, $cmd, $chan)= @_;
# print LOGFILE "$who ${cmd}ed $chan\n";
print LOGFILE "$who ${cmd}ed $chan at ",&ctime(time);
}
sub ParseInvite {
local ($who, $args) = @_;
print LOGFILE "$who invited me to $args\n";
&ircclient'notice($who,"Sorry, I'd rather stay here.");
}
sub ParsePriv {
local($src,$args) = @_;
local($target,$message) = split(/ /,$args,2);
$target = "me" if $target =~ /$nick/i;
$message = &StripLeadingColon($message);
print LOGFILE "$src told $target \"$message\".\n";
}
sub ParseNamReply {
local ($src,$args) = @_;
print LOGFILE "NAMREPLY = $args\n";
}
sub ParseNotice {
local ($src,$args) = @_;
local($target,$message) = split(/ /,$args,2);
$target = "me" if $target =~ /$nick/i;
$message = &StripLeadingColon($message);
print LOGFILE "$src NOTICEd $target \"$message\".\n";
}
sub ParseChanMsg {
local($src,$target,$message) = @_;
print LOGFILE "$src told $target \"$message\".\n";
}
sub ParseWallops {
local ($src,$args) = @_;
print LOGFILE "$src walloped $args at ",&ctime(time);
}
sub ParseWall {
local ($src,$args) = @_;
print LOGFILE "$src WALLed $args\n";
}
sub ParseQuit {
local ($src,$args) = @_;
print LOGFILE "$src QUIT at ",&ctime(time);
}
sub Quit {
&ircclient'privmsg($lord,"Hey, man, I'm outa here.");
&ircclient'quit;
}